package com.usian.article.controller;/*
 *文件名：AuthorController
 *创建者：宋璟
 *创建时间:2023/2/8 8:53
 *描述: TODO
 */


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.api.article.AuthorControllerApi;
import com.usian.article.service.impl.AuthorServiceImpl;
import com.usian.model.article.pojos.ApAuthor;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/author")
public class AuthorController implements AuthorControllerApi {

    @Autowired
    private AuthorServiceImpl service;

    @Override
    @GetMapping("/findByUserId/{id}")
    public ApAuthor findByUserId(@PathVariable("id") Integer id) {
        return service.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(id != null ,ApAuthor::getUserId,id));

    }

    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody ApAuthor apAuthor) {
        if (apAuthor == null)return service.errorParam;
        service.save(apAuthor);
        return ResponseResult.okResult(apAuthor);
    }


}
